// Copyright (c) Microsoft Corporation.  All rights reserved.
#include "StdAfx.h"
#include "EventSourceNotificationUtility.h"

#include "SideShowServiceType.h"
#include "SideShowServiceTypeTypes.h"
#include "SideShowServiceTypeProxy.h"


CEventSourceNotificationUtility* CEventSourceNotificationUtility::m_pInstance = NULL;

//------------------------------------------------------------------------------
// CEventSourceNotificationUtility::CEventSourceNotificationUtility
//      Constructor
//------------------------------------------------------------------------------
CEventSourceNotificationUtility::CEventSourceNotificationUtility(void)
{
    m_pSideShowServiceEventSource = NULL;

    m_bInitialized = FALSE;
}

//------------------------------------------------------------------------------
// CEventSourceNotificationUtility::~CEventSourceNotificationUtility
//      Destructor
//------------------------------------------------------------------------------
CEventSourceNotificationUtility::~CEventSourceNotificationUtility(void)
{
    if (NULL != m_pSideShowServiceEventSource)
    {
        m_pSideShowServiceEventSource->Release();
        m_pSideShowServiceEventSource = NULL;
    }
}

//------------------------------------------------------------------------------
// CEventSourceNotificationUtility::GetInstance
//      Get unique instance of singleton class
//------------------------------------------------------------------------------
CEventSourceNotificationUtility* CEventSourceNotificationUtility::GetInstance()
{
    if (NULL == m_pInstance)
    {
        m_pInstance =  new CEventSourceNotificationUtility;
    }

    return m_pInstance;
}

//------------------------------------------------------------------------------
// CEventSourceNotificationUtility::Initialize
//      Create and initialize DPWS event source instance
//------------------------------------------------------------------------------
void CEventSourceNotificationUtility::Initialize(IWSDDeviceHost* pDeviceHostRef)
{
    if (m_bInitialized)
    {
        return;
    }

    if (NULL == m_pSideShowServiceEventSource)
    {
        m_pSideShowServiceEventSource = new CSideShowServiceTypeEventSource;
        m_pSideShowServiceEventSource->Init(pDeviceHostRef, L"uri:SS");
    }

    m_bInitialized = TRUE;
}

//------------------------------------------------------------------------------
// CEventSourceNotificationUtility::DestroyInstance
//      Destroy unique instance of singleton class
//------------------------------------------------------------------------------
void CEventSourceNotificationUtility::DestroyInstance()
{
    if ( NULL != m_pInstance )
    {
        delete m_pInstance;
        m_pInstance = NULL;
    }
}

//------------------------------------------------------------------------------
// CEventSourceNotificationUtility::SideShowButtonPressedEvent
//      Sending button clicking event notification to DPWS client(event subscriber)
//------------------------------------------------------------------------------
HRESULT CEventSourceNotificationUtility::SideShowButtonPressedEvent(const CString& csButtonID, const CString& csClientID)
{
    SIDE_SHOW_BUTTON_PRESS_TYPE sideshowEvent;
    sideshowEvent.Any = NULL;
    sideshowEvent.Button = csButtonID;
    sideshowEvent.ClientID = csClientID;
    return m_pSideShowServiceEventSource->SideShowButtonPressedEvent(&sideshowEvent); 
}